using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Xml;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace Pet
{
    public class DBHelper
    {
        #region
        [DllImport("kernel32")]
        private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);

        [DllImport("kernel32")]
        private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);

        private static string configFilePath = Application.StartupPath + "\\config.ini";
        #endregion

        //public static string db;
        private static string sql = getconnstr();
        public static SqlConnection con = new SqlConnection(sql);
        public static string getconnstr()
        {
            string db = "UFSystem";
            StringBuilder sb1 = new StringBuilder(255);
            StringBuilder sb2 = new StringBuilder(255);
            StringBuilder sb3 = new StringBuilder(255);
            GetPrivateProfileString("config", "server", "", sb1, 255, configFilePath);
            GetPrivateProfileString("config", "id", "", sb2, 255, configFilePath);
            GetPrivateProfileString("config", "pwd", "", sb3, 255, configFilePath);
            string connstr = string.Format("Data Source={0};Initial Catalog={1};User ID={2};Password={3}", sb1, db, sb2, sb3);
            return connstr;
        }
    }
}
